/*
 * $Author: isan.wong@gmail.com $
 * $Date: 2011-07-29 01:03:06 +0000 (Fri, 29 Jul 2011) $
 * $Rev: 13 $
 * $URL: http://capitalbio-smd.googlecode.com/svn/src/com/capitalbio/smd/gui/AdPane.java $
 */

package com.capitalbio.smd.gui;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 广告
 * @author Wang Lei
 */
public class AdPane extends JPanel {
	private static final long serialVersionUID = 1L;
	protected Log log = LogFactory.getLog(this.getClass());

	public AdPane() {
		setBorder(new EmptyBorder(0, 0, 0, 0));
		setLayout(new BorderLayout());

		JButton adButton = new JButton(new ImageIcon(getImage()));
		adButton.setContentAreaFilled(false);
		adButton.setPreferredSize(new Dimension(0, 100));
		adButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
		
		adButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Desktop desktop = Desktop.getDesktop();
				try {
					URI uri = new URI("");
			        desktop.browse(uri);
			    }
				catch (URISyntaxException e){
			        log.error(e);
			    }
				catch (IOException e){
					log.error(e);
			    }

			}
		});
		
		add(adButton, BorderLayout.CENTER);
	}
	
	private Image getImage() {
		Image image = null;
		try {
			URL imageURL = new URL("");
			InputStream is = imageURL.openConnection().getInputStream();
			image = ImageIO.read(is);
		}
		catch (MalformedURLException e) {
			log.error(e);
		}
		catch (IOException e) {
			log.error(e);
		}
		
		return image;
	}
}
